import {
    SETCHATLOG,
    UPDATECHATLOGCONTENT,
    APPENDCHATLOG
} from '../actions/msg';

function chatLog(state = {
    list: []
}, action) {
	switch (action.type) {
        case SETCHATLOG:
            let chaters = [];
            for(let i=0; i<action.lists.length; i++){
                let uid = action.lists[i].uid;
                chaters[uid] = [{
                    uid: uid,
                    time: action.lists[i].time,
                    content: action.lists[i].content
                }];
            }
			return Object.assign({},state, {
				list: chaters
            });
        case UPDATECHATLOGCONTENT:
            state.list[action.tuid] = action.lists;
            return state;
        case APPENDCHATLOG:
            state.list[action.uid].push({
                uid: action.fuid,
                time: action.time,
                content: action.content
            });
            return state;
		default:
			return state
	}
}

export default chatLog;